package org.cangku.util;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;

public class Upload {
    public static String simUpload(MultipartFile file, HttpServletRequest request) throws IllegalStateException, IOException{

                 /*if(!file.isEmpty()){
                         String path = request.getSession().getServletContext().getRealPath("/upload");
                         //定义文件
                         File parent = new File(path);
                         if(!parent.exists()) parent.mkdirs();

                         HashMap<String, Object> map = new HashMap<String,Object>();

                         String oldName = file.getOriginalFilename();

                         long size = file.getSize();

                         //使用TmFileUtil文件上传工具获取文件的各种信息
                         //优化文件大小
                         //String sizeString = TmFileUtil.countFileSize(size);
                         //获取文件后缀名
                         //String ext = TmFileUtil.getExtNoPoint(oldName);
                         //随机重命名，10位时间字符串
                         String newFileName = TmFileUtil.generateFileName(oldName, 10, "yyyyMMddHHmmss");

                         String url = "upload/"+newFileName;

                         //文件传输，parent文件
                         file.transferTo(new File(parent, newFileName));

                         map.put("oldname",oldName);//文件原名称
                         map.put("ext",ext);
                         map.put("size",sizeString);
                         map.put("name",newFileName);//文件新名称
                         map.put("url",url);

                         //以json方式输出到页面
                         return JSONUtil.serialize(map);
                     }else{
                         return null;
                     }*/

                 return "";
             }
}
